const Koa = require('koa');
const app  = new Koa();

app.use(async (ctx) => {
    if(ctx.url === '/') {
        ctx.cookies.set(
            'MyName','xgp',{
                domain: '127.0.0.1',
                path: '/index',
                maxAge: 1000*60*60*24,
                expires: new Date('2020-12-31'),
                httpOnly: false,
                overwrite: false
            }
        );
        ctx.body = 'cookie is ok';
    }else {
        if(ctx.cookies.get('MyName')) {
            ctx.body = ctx.cookies.get('MyName');
        }else {
            ctx.body = 'hello';
        }
    }
});

// 监听端口
app.listen(3000,() => {
    //监听回调
    console.log('app is start at port 3000');
});
